package cn.kgc.controller;

import cn.kgc.entity.Books;
import cn.kgc.service.BooksService;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 帅气逼人程序员
 * @version 1.0
 * @date 2023/3/2 - 18:56
 */
@Controller
public class BooksController {


    @Resource
    private BooksService booksService;

    @GetMapping("/index")
    public String index(Model model){
        System.out.println("进来了控制层");
        List<Books>books=booksService.getAllBooks();
        System.out.println(books);
        model.addAttribute("books",books);
        return "index";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping("/403")
    public String error403(){
        return "403";
    }

    @Secured({"ROLE_admin"})
    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @Secured({"ROLE_admin"})
    @RequestMapping("/up")
    public String up(){
        return "up";
    }

    @Secured({"ROLE_admin"})
    @RequestMapping("/del")
    public String del(){
        return "del";
    }

}
